package com.blog.controller;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BaseTools {

	static String phoneReg = "\\bNokia|SAMSUNG|MIDP-2|CLDC1.1|SymbianOS|MAUI|UNTRUSTED/1.0"  
		    +"|Windows CE|iPhone|iPad|Android|BlackBerry|UCWEB|ucweb|BREW|J2ME|YULONG|YuLong|COOLPAD|TIANYU|TY-"  
		    +"|K-Touch|Haier|DOPOD|Lenovo|LENOVO|HUAQIN|AIGO-|CTC/1.0"  
		    +"|CTC/2.0|CMCC|DAXIAN|MOT-|SonyEricsson|GIONEE|HTC|ZTE|HUAWEI|webOS|GoBrowser|IEMobile|WAP2.0\\b";    
	static String tableReg = "\\b(ipad|tablet|(Nexus 7)|up.browser"   
		            +"|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";    
		       
		    //移动设备正则匹配：手机端、平板  
	static Pattern phonePat = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);    
	static Pattern tablePat = Pattern.compile(tableReg, Pattern.CASE_INSENSITIVE);

	public String chooseTheme(String theme,String vmType) {
		
		//获取cookies的主题样式
		System.out.println("主题是:"+theme+",页面"+vmType);
		//UA
		//System.out.println("wap_theme/index");
		//return "wap_theme/index";
		
		
		//"mobile"显示手机主题
		if("mobile".equals(theme)){
			return vmType;
		}
	    
		
		//非手机主题
		//默认主题
		if("".equals(theme)||theme==null){
			System.out.println("activeness_theme/"+vmType);
			//""默认主题设置为activeness
			return "air_theme/"+vmType;
		}else if("default".equals(theme)){
			return "original_theme/"+vmType;//"default"选择原始主题
		}else{
			return theme+"_theme/"+vmType;//theme开头的主题
		}
		//根据ua 移动版主题
		
		 
		
	}
	
	
    public static boolean checkMobile(String userAgent){    
        if(null == userAgent){    
            userAgent = "";    
        }    
        // 匹配    
        Matcher matcherPhone = phonePat.matcher(userAgent);    
        Matcher matcherTable = tablePat.matcher(userAgent);    
        if(matcherPhone.find() || matcherTable.find()){    
            return true;   //移动设备 
        } else {    
            return false;    
        }    
    }  

}
